<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="设备ID（如燃气管道编号）" prop="deviceId">
                        <el-input v-model="dataForm.deviceId" placeholder="设备ID（如燃气管道编号）"></el-input>
                </el-form-item>
                <el-form-item label="设备类型（如燃气管道、燃烧设备）" prop="deviceType">
                        <el-input v-model="dataForm.deviceType" placeholder="设备类型（如燃气管道、燃烧设备）"></el-input>
                </el-form-item>
                <el-form-item label="泄漏报警状态（0：无报警，1：报警）" prop="leakAlarm">
                        <el-input v-model="dataForm.leakAlarm" placeholder="泄漏报警状态（0：无报警，1：报警）"></el-input>
                </el-form-item>
                <el-form-item label="火焰状态（如正常、熄火）" prop="flameStatus">
                        <el-input v-model="dataForm.flameStatus" placeholder="火焰状态（如正常、熄火）"></el-input>
                </el-form-item>
                <el-form-item label="燃烧效率（百分比）" prop="combustionEfficiency">
                        <el-input v-model="dataForm.combustionEfficiency" placeholder="燃烧效率（百分比）"></el-input>
                </el-form-item>
                <el-form-item label="数据采集时间" prop="collectionTime">
                        <el-date-picker
                                v-model="dataForm.collectionTime"
                                type="datetime"
                                placeholder="数据采集时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="备注信息" prop="remark">
                        <el-input v-model="dataForm.remark" placeholder="备注信息"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    deviceId: null,
                    deviceType: null,
                    leakAlarm: null,
                    flameStatus: null,
                    combustionEfficiency: null,
                    collectionTime: null,
                    remark: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
                    ],
                    deviceId: [
                        { required: true, message: '设备ID（如燃气管道编号）不能为空', trigger: 'blur' }
                    ],
                    deviceType: [
                        { required: true, message: '设备类型（如燃气管道、燃烧设备）不能为空', trigger: 'blur' }
                    ],
                    leakAlarm: [
                        { required: true, message: '泄漏报警状态（0：无报警，1：报警）不能为空', trigger: 'blur' }
                    ],
                    flameStatus: [
                        { required: true, message: '火焰状态（如正常、熄火）不能为空', trigger: 'blur' }
                    ],
                    combustionEfficiency: [
                        { required: true, message: '燃烧效率（百分比）不能为空', trigger: 'blur' }
                    ],
                    collectionTime: [
                        { required: true, message: '数据采集时间不能为空', trigger: 'blur' }
                    ],
                    remark: [
                        { required: true, message: '备注信息不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppGasEquipmentMonitor/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appgasequipmentmonitor
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppGasEquipmentMonitor/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>